package com.run.runbbs.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.run.runbbs.common.dto.AbnormalIndexDto;
import com.run.runbbs.common.lang.Result;
import com.run.runbbs.entity.IndexValue;
import com.run.runbbs.entity.UserInfo;
import com.run.runbbs.service.IndexValueService;
import com.run.runbbs.service.UserInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/unnormalData")
public class UnnormalDataController {

    @Autowired
    private IndexValueService indexValueService;
    @Autowired
    private UserInfoService userInfoService;

    @GetMapping("list")
    public Result list() {
        List<IndexValue> list=indexValueService.getAbnormalTemperature();
        List<AbnormalIndexDto> res=new ArrayList<>();
        for(IndexValue indexValue : list){
            AbnormalIndexDto abnormalIndexDto=new AbnormalIndexDto();
            BeanUtils.copyProperties(indexValue,abnormalIndexDto);
            UserInfo userInfo=userInfoService.getOne(new QueryWrapper<UserInfo>().eq("user_id",indexValue.getUserId()));
//            log.info("{}", userInfo);
//            log.info("{}", abnormalIndexDto);
            //暂时写死
            abnormalIndexDto.setIndexType("体温");
            BeanUtils.copyProperties(userInfo,abnormalIndexDto);
            res.add(abnormalIndexDto);
        }

        return Result.success(res);
    }
}
